From eca88fd2f66b548b9ee9bd6e1720b6622fd8e7ca Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sat, 6 Jun 2015 18:22:36 +1000 Subject: [PATCH] test: point doc tests to the main library, for cyclic deps. Previously a dependency cycle like `a` <-(normal)- `b` <-(dev)- `a` would mean that importing `b` in `a`'s doc test would fail because the original `a` library was not found. Fixes #1686. --- src/cargo/ops/cargo_test.rs | 10 ++++---- tests/test_cargo_test.rs | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 631ffae52..a911058fb 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -38,13 +38,13 @@ pub fn run_tests(manifest_path: &Path, let mut p = try!(compile.rustdoc_process(&compile.package)); p.arg("--test").arg(lib) .arg("--crate-name").arg(&crate_name) - .arg("-L").arg(&{ - let mut arg = OsString::from("dependency="); - arg.push(&compile.deps_output); - arg - }) .cwd(compile.package.root()); + for &rust_dep in &[&compile.deps_output, &compile.root_output] { + let mut arg = OsString::from("dependency="); + arg.push(rust_dep); + p.arg("-L").arg(arg); + } for native_dep in compile.native_dirs.values() { p.arg("-L").arg(native_dep); } diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 0b6e21c3c..534890313 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -1582,3 +1582,51 @@ test!(dylib_doctest2 { assert_that(p.cargo_process("test"), execs().with_stdout("")); }); + +test!(cyclic_dev_dep_doc_test { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dev-dependencies] + bar = { path = "bar" } + "#) + .file("src/lib.rs", r#" + //! ``` + //! extern crate bar; + //! ``` + "#) + .file("bar/Cargo.toml", r#" + [package] + name = "bar" + version = "0.0.1" + authors = [] + + [dependencies] + foo = { path = ".." } + "#) + .file("bar/src/lib.rs", r#" + extern crate foo; + "#); + assert_that(p.cargo_process("test"), + execs().with_stdout(format!("\ +{compiling} foo v0.0.1 ([..]) +{compiling} bar v0.0.1 ([..]) +{running} target[..]foo[..] + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured + +{doctest} foo + +running 1 test +test _0 ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured + +", compiling = COMPILING, running = RUNNING, doctest = DOCTEST))) +}); -- 2.30.2